
import {test,swipers,news,gives,details,carts,searchcarts,cartmenus,mineusers,addcarts,removecarts,removealls} from '@/api/api_one.js'

const state = {
  vuexStr:'',
  // 首页轮播图
  swipers:'',
  // 首页最新商品
  news:'',
  // 首页推荐商品
  gives:'',
  // 商品详情
  details:'',
  // 购物车列表
  carts:'',
  // 商品搜索
  searchcarts:'',
  // 分类列表商品
  cartmenus:'',
  // 登录页面
  mineusers:'',
  // 添加购物车
  addcarts:'',
  // 删除购物车数据
  removecarts:'',
  // 清空购物车
  removealls:''
}

const mutations = {
  SET_VUEXTEST:(state, data)=>{
    state.vuexStr = data
  },
  // 首页轮播图
  SET_VUEXSWIPER:(state,data)=>{
	  state.swipers = data
  },
  // 首页最新商品
  SET_VUEXNEWS:(state,data)=>{
  	  state.news = data
  },
  // 首页推荐商品
  SET_VUEXGIVES:(state,data)=>{
  	  state.gives = data
  },
  // 商品详情
  SET_VUEXDETAILS:(state,data)=>{
  	  state.details = data
  },
  // 购物车列表
  SET_VUEXCARTS:(state,data)=>{
  	  state.carts = data
  },
  // 商品搜索
  SET_VUEXSEARCHCARTS:(state,data)=>{
  	  state.searchcarts = data
  },
  // 分类列表商品
  SET_VUEXCARTMENUS:(state,data)=>{
  	  state.cartmenus = data
  },
  // 登录页面
  SET_VUEXMINEUSER:(state,data)=>{
	  state.mineusers = data
  },
  // 添加购物车
  SET_VUEXADDCART:(state,data)=>{
	  state.addcarts = data
  },
  // 购物车删除
  SET_VUEXREMOVECART:(state,data)=>{
  	  state.removecarts = data
  },
  // 清空购物车
  SET_VUEXREMOVEALL:(state,data)=>{
  	  state.removealls = data
  }
}

const actions = {
  vuexTest({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testState = test()
      if(testState){
        commit("SET_VUEXTEST",testState+data)
        resolve(testState)
      }else{
        reject('失败')
      }
    })
  },
  // 首页轮播图
  vuexSwiper({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStates = swipers()
      if(testStates){
        commit("SET_VUEXSWIPER",testStates+data)
        resolve(testStates)
      }else{
        reject('失败')
      }
    })
  },
  // 首页最新商品
  vuexNew({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStatess = news()
      if(testStatess){
        commit("SET_VUEXNEWS",testStatess+data)
        resolve(testStatess)
      }else{
        reject('失败')
      }
    })
},
// 首页推荐商品
  vuexGive({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStatesss = gives()
      if(testStatesss){
        commit("SET_VUEXNEWS",testStatesss+data)
        resolve(testStatesss)
      }else{
        reject('失败')
      }
    })
},
// 商品详情
  vuexDetail({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStatesss = details(data)
      if(testStatesss){
        commit("SET_VUEXNEWS",testStatesss+data)
        resolve(testStatesss)
      }else{
        reject('失败')
      }
    })
},
// 购物车列表
  vuexCart({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStatesss = carts(data)
      if(testStatesss){
        commit("SET_VUEXCARTS",testStatesss+data)
        resolve(testStatesss)
      }else{
        reject('失败')
      }
    })
},
// 商品搜索
  vuexSearchcart({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStatesss = searchcarts(data)
      if(testStatesss){
        commit("SET_VUEXSEARCHCARTS",testStatesss+data)
        resolve(testStatesss)
      }else{
        reject('失败')
      }
    })
},
// 分类列表商品
  vuexCartmenu({commit},data){
    
    // return test()
    return new Promise((resolve,reject)=>{
      let testStatesss = cartmenus(data)
      if(testStatesss){
        commit("SET_VUEXCARTMENUS",testStatesss+data)
        resolve(testStatesss)
      }else{
        reject('失败')
      }
    })
},
// 登录页面
  vuexMineuser({commit},data){
	  return new Promise((resolve,reject)=>{
		  let testStatess = mineusers(data)
		  if(testStatess){
			  commit("SET_VUEXMINEUSER",testStatess+data)
			  resolve(testStatess)
		  }else{
			  reject('失败')
		  }
	  })
  },
  // 添加购物车
  vuexAddcart({commit},data){
  	  return new Promise((resolve,reject)=>{
  		  let testStatess = addcarts(data)
  		  if(testStatess){
  			  commit("SET_VUEXADDCART",testStatess+data)
  			  resolve(testStatess)
  		  }else{
  			  reject('失败')
  		  }
  	  })
  },
  // 删除购物车数据
  vuexRemovecart({commit},data){
  	  return new Promise((resolve,reject)=>{
  		  let testStatess = removecarts(data)
  		  if(testStatess){
  			  commit("SET_VUEXREMOVECART",testStatess+data)
  			  resolve(testStatess)
  		  }else{
  			  reject('失败')
  		  }
  	  })
  },
  // 清空购物车
  vuexRemoveall({commit},data){
  	  return new Promise((resolve,reject)=>{
  		  let testStatess = removealls(data)
  		  if(testStatess){
  			  commit("SET_VUEXREMOVEALL",testStatess+data)
  			  resolve(testStatess)
  		  }else{
  			  reject('失败')
  		  }
  	  })
  }

}
export default {
  state,
  mutations,
  actions
}
